package br.com.cdto.DAO;

import java.util.List;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

import br.com.cdto.entity.Cornea;
import br.com.cdto.entity.Exame;
import br.com.cdto.entity.Orgao;

/**
 * Session Bean implementation class CorneaDAO
 */
@Stateless
@LocalBean
public class CorneaDAO implements CorneaDAOLocal {
	@PersistenceContext
	public EntityManager entityManager;

	public CorneaDAO() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public void salvaCornea(Cornea c) {
		Orgao o = c;
		entityManager.persist(o);

	}

	@Override
	public List<Cornea> consultaCornea() {
		TypedQuery<Cornea> query = entityManager.createQuery("select o from Cornea o where o.status = :status order by o.dataRetirada", Cornea.class);
		query.setParameter("status", "Ativo");
		List<Cornea> list = query.getResultList();
		for (Cornea cornea : list) {
			System.out.println(cornea.getDoador().getExames().size());
			for(Exame e : cornea.getDoador().getExames()){
				System.out.println(e.getAtributos().size());
			}
		}
		return list;
	}

}
